<?php 
	Connection::getConnect();
	$sql = "SELECT *,(SELECT COUNT(base_cat_id) FROM item_category ci WHERE ci.base_cat_id=ic.icid) AS subs FROM item_category ic WHERE base_cat_id=0 LIMIT 6 ";
    Connection::setQuery($sql);
	$categories = Connection::fetchAll(MYSQL_ASSOC);
	$lastid=0;
	
	function getSubs($id){
		$sql = "SELECT *,(SELECT COUNT(base_cat_id) FROM item_category ci WHERE ci.base_cat_id=$id) AS subs FROM item_category WHERE base_cat_id=$id LIMIT 9";
    	Connection::setQuery($sql);
		$subcategories = Connection::fetchAll(MYSQL_ASSOC);
		foreach ($subcategories as $subcategory){
			echo '<li><a href="#">' . $subcategory['name'] . '</a></li>';
		}
		if ($subcategories[0]["subs"] > 9)
			echo '<li><a href="#">More</a></li>';
	}
?>
